//2009/08/29 01:54:01
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class ContiguousCacheEasy
{
public:
    int bytesRead(int n, int k, vector <int> addresses)
    {
		int base = 0;
		int res = 0;
		int nb;
		int d;
		for(int i=0; i<addresses.size(); i++)
		{
			if(base <= addresses[i] && addresses[i] < base + k) continue;
			d = INT_MAX; 
			nb = 0;
			for(int j=max(0, addresses[i]-k+1); j<=addresses[i]; j++)
			if(abs(j-base) < d)
			{
				d = abs(j-base);
				nb = j;
			}
			res += min(d,k);
			base = nb;
		}
		return res;
    }
};
// From ebd's;
